<?php
$base_path = './';
$admin_path = '../';
$main_path = '../../';

require_once($admin_path ."model/Kierunki.php");
require_once($admin_path ."model/Specjalizacja.php");


$model_kierunki = new Model_Kierunki();
$directions = $model_kierunki->getAll();
if(isset($_GET['direction'])){
    $direction_id = $_GET['direction'];
}else{
    $direction_id = $directions[0]['id']; // pierwszy z listy
}
$direction_selected = $direction_id;

$model_specjalizacja = new Model_Specjalizacja();
$specialization = $model_specjalizacja->getAllForKierunek($direction_id);
if(isset($_POST['action'])){
    $action = $_POST['action'];
    if($action == 'edit'){
      //  var_dump($_POST,$direction_selected);die;
       header('Location: '.$base_path.'specialization_edit?direction='.$direction_selected.'&spec='.$_POST['spec_id']);die;
      // header('Location: '.$base_path."specialization_edit?direction=1&spec=1");die;
    }else if($action == 'delete'){
        $spec_id = $_POST['spec_id'];
        $model_specjalizacja->delete($spec_id);
    }else if($action == 'add'){
        $nazwa = $_POST['spec'];
        $model_specjalizacja->insert($nazwa, $direction_id);
    }
    header('Location:'.$base_path.'specialization?direction='.$direction_id);
}

require_once($admin_path."view/specialization.php");
?>
